/*
 * @Description: 
 * @Version: 2.0
 * @Autor: lxc
 * @Date: 2020-12-15 13:45:34
 * @LastEditors: lxc
 * @LastEditTime: 2020-12-16 17:30:50
 */
/*
 * @Description: 
 * @Version: 2.0
 * @Autor: lxc
 * @Date: 2020-12-15 13:45:57
 * @LastEditors: lxc
 * @LastEditTime: 2020-12-15 14:24:02
 */
const Validator = require("validator");
const isEmpty = require('./is-empty');

module.exports = function validateLoginInput(data) {
    let errors = {};

    data.email = !isEmpty(data.email) ? data.email : '';
    data.password = !isEmpty(data.password) ? data.password : '';
    
    if (Validator.isEmpty(data.email)) {
        errors.msg = "邮箱不能为空！"
    }else if (!Validator.isEmail(data.email)) {
        errors.msg = "邮箱不合法！"
    } else if (Validator.isEmpty(data.password)) {
        errors.msg = "密码不能为空！"
    }
    return {
        errors,
        isValid: isEmpty(errors)
    };
}